// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import fastclick from 'fastclick'
import Mint from 'mint-ui';
import 'mint-ui/lib/style.css'
import './assets/less/public.less'
import axios from 'axios';

fastclick.attach(document.body)

Vue.use(Mint);
Vue.prototype.mint = Mint;




// 点滴渠H5测试
// Vue.prototype.host =  '/api';


// 点滴渠H5正式
Vue.prototype.host =  'h5-api';



Vue.prototype.ajax = function(options){
	let that = this;
    return new Promise((resolve,reject)=>{
    	that.mint.Indicator.open();
       	axios({
            url: that.host + options.url,
            method: 'POST',
		    headers: options.headers,
		    data: options.data,
		}).then(function(res){
			that.mint.Indicator.close();
			if(res.status == 200 ){
		      	if(res.data.code == '0'){
		      		resolve(res.data)	
		      	}else{
		      		reject(res.data)
		      		that.mint.Toast(res.data.message);
		      	}
		    }
		}).catch(function(error){
		    if( error.response ){
		      	let code = error.response.status;
		      	if (code == '404') {
		      		that.mint.Toast("接口不存在");
		      	} else {
		      		that.mint.Toast("服务器错误");
		     	}
		    }
		})
    })
}



Vue.prototype.$ajax = function(options){
	let that = this;
    that.mint.Indicator.open();
   	axios({
        url: that.host + options.url,
        method: 'POST',
	    headers: options.headers,
	    data: options.data,
	}).then(function(res){
		that.mint.Indicator.close();
		if(res.status == 200 ){
	      	if(res.data.code == '0'){
	      		options.success({
		        	code: res.data.code,
		        	data: res.data.data
		     	});	
	      	}else{
	      		options(res.data)
	      		that.mint.Toast(res.data.message);
	      	}
	    }
	}).catch(function(error){
	    if( error.response ){
	      	let code = error.response.status;
	      	if (code == '404') {
	      		that.mint.Toast("接口不存在");
	      	} else {
	      		that.mint.Toast("服务器错误");
	     	}
	    }
	})
}















Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
